let set = new Set([1, 2, 3, 4]);

let obj = {
  1: "hdcms",
  1: "houdunren",
};

let hd = {
  [obj]: "jason",
};

// console.log(hd.toString());
console.log(hd[obj.toString()]); //这样访问到jason数据

let setOne = new Set(["hdcms", "houdunren"]);
// console.log(setOne.clear());
console.log(setOne.delete("hdcms")); // 返回true还是false
console.log(setOne.size); // 返回数组中元素的个数
console.log(setOne.values()); // 查看数组中的元素
console.log(setOne.has("houdunren")); // 是否有该元素？

let hd1 = new Set("123456789");
console.log(hd1);
hd1 = new Set([...hd1].filter((item) => item < 5));
console.log(hd1);

let hd2 = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
console.log([...new Set(hd2)]);

// 可以用for of 去遍历Set，Set是一个迭代对象
for (const val of setOne) {
  console.log(val);
}

let a = new Set([1, 2, 3, 4, 5, 6]);
let b = new Set([4, 5, 6]);
// 并集 去掉重复的元素了
console.log(new Set([...a, ...b]));
// 交集，数组a有，数组b也有 4 5 6
console.log(
  new Set(
    [...a].filter(function (item) {
      return b.has(item);
    })
  )
);

// WeakSet 保存的是引用类型
let nodes = new WeakSet();
/*
let divs = document.querySelector("div");
divs.forEach((element) => {
  nodes.add(element);
});
nodes.delete(divs[0]);
console.log(nodes.has(divs[0]));
*/
